package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.service.prop.PropService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ywxie
 * @date 2019/12/26 17:00
 * @description
 */
@RestController
@RequestMapping("/api/userprop")
public class UserPropController {

    private PropService propService;

    @Autowired
    public void setPropService(PropService propService) {
        this.propService = propService;
    }

    @GetMapping("")
    public BaseRsp getUserPropRecord(@RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
                                     @RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset,
                                     @RequestParam(value = "accountId", required = false) Long uid,
                                     @RequestParam(value = "prop_type", required = false) Integer propType,
                                     @RequestParam(value = "state", required = false) Byte state,
                                     @RequestParam(value = "start_time", required = false) String startTime,
                                     @RequestParam(value = "end_time", required = false) String endTime){
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("limit", limit.toString());
        paramMap.put("offset", offset.toString());
        if (uid != null){
            paramMap.put("uid", uid.toString());
        }
        if (propType != null){
            paramMap.put("prop_type", propType.toString());
        }
        if (state != null){
            paramMap.put("state", state.toString());
        }
        if (startTime != null){
            paramMap.put("start_time", startTime);
        }
        if (endTime != null){
            paramMap.put("end_time", endTime);
        }
        return propService.listUserPropAdmin(paramMap);
    }

    @GetMapping("/config")
    public BaseRsp getPropTypeConfig(){
        return propService.listPropTypeCfg();
    }
}
